/**
*  \file instrument.c
*
*  \brief
*
*  \author Qilong Huang
*
*
*/
/*===============================================[ private includes  ]================================================*/

#include <stdio.h>
#include <string.h>
#include "instrument.h"
#include "lcd.h"
#include "CAN_canopen.h"
#include "BDI.h"
//#include "menu.h"
//#include "CustomArrayData.h"
//#include "key.h"
//#include "hourmeter.h"
//#include "var_tbl.h"
//#include "icons.h"

/*===============================================[ private defines   ]================================================*/
U8 batt_flash_counter = 0;

/*===============================================[ private datatypes ]================================================*/

/*===============================================[ private variables ]================================================*/
/**
* @brief	Display battary percent and level
* @param	u8	bat_col: the colum of battary.
* @note     none
* @retval   none  
            0%~19%:			    level1
            20%~39%:			level2
            40%~59%:			level3
            60%~79%:			level4
            80%~100%:			level5
*/
void Display_battary_col( U8 bat_col)
{
    U8 i, j, k;
    if(bat_col > 100)
    {
        return;
    }
    else
    {
        i = bat_col / 100;
        j = (bat_col - i * 100) / 10;
        k = bat_col - i * 100 - j * 10;
        if(i == 0)
        {
            LCD_draw_number( 0, 0, SIZE_22, i, HIDE_ENABLE );
        } 
        else
        {
            LCD_draw_number( 0, 0, SIZE_22, i, HIDE_DISABLE );
        }
        if((j == 0) && (i == 0))
        {
            LCD_draw_number(0, 17, SIZE_22, j, HIDE_ENABLE );
        }
        else
        {
            LCD_draw_number(0, 17, SIZE_22, j, HIDE_DISABLE );
        }
        LCD_draw_number(0, 34, SIZE_22, k, HIDE_DISABLE );		
        LCD_draw_sign(0,51,SIZE_22,0);
        if((bat_col >= 80) && (bat_col <= 100))
        {
            LCD_draw_rectangle( 80, 3, 30, 3, Black, HIDE_DISABLE);
            LCD_draw_rectangle( 80, 8, 24, 3, Black, HIDE_DISABLE);
            LCD_draw_rectangle( 80, 13, 15, 3, Black, HIDE_DISABLE);
            LCD_draw_rectangle( 80, 18, 9, 3, Black, HIDE_DISABLE);
            LCD_draw_rectangle( 80, 23, 5, 3, Black, HIDE_DISABLE);
        }
        else if((bat_col >= 60) && (bat_col <= 79))
        {
            LCD_draw_rectangle( 80, 3, 30, 3, White, HIDE_ENABLE);
            LCD_draw_rectangle( 80, 8, 24, 3, Black, HIDE_DISABLE);
            LCD_draw_rectangle( 80, 13, 15, 3, Black, HIDE_DISABLE);
            LCD_draw_rectangle( 80, 18, 9, 3, Black, HIDE_DISABLE);
            LCD_draw_rectangle( 80, 23, 5, 3, Black, HIDE_DISABLE);
        }
        else if((bat_col >= 40) && (bat_col <= 59))
        {
            LCD_draw_rectangle( 80, 3, 30, 3, White, HIDE_ENABLE);
            LCD_draw_rectangle( 80, 8, 24, 3, White, HIDE_ENABLE);
            LCD_draw_rectangle( 80, 13, 15, 3, Black, HIDE_DISABLE);
            LCD_draw_rectangle( 80, 18, 9, 3, Black, HIDE_DISABLE);
            LCD_draw_rectangle( 80, 23, 5, 3, Black, HIDE_DISABLE);
        }
        else if((bat_col >= 20) && (bat_col <= 39))
        {
            LCD_draw_rectangle( 80, 3, 30, 3, White, HIDE_ENABLE);
            LCD_draw_rectangle( 80, 8, 24, 3, White, HIDE_ENABLE);
            LCD_draw_rectangle( 80, 13, 15, 3, White, HIDE_ENABLE);
            LCD_draw_rectangle( 80, 18, 9, 3, Black, HIDE_DISABLE);
            LCD_draw_rectangle( 80, 23, 5, 3, Black, HIDE_DISABLE);
        }
        else
        {
            LCD_draw_rectangle( 80, 3, 30, 3, White, HIDE_ENABLE);
            LCD_draw_rectangle( 80, 8, 24, 3, White, HIDE_ENABLE);
            LCD_draw_rectangle( 80, 13, 15, 3, White, HIDE_ENABLE);
            LCD_draw_rectangle( 80, 18, 9, 3, White, HIDE_ENABLE);
            LCD_draw_rectangle( 80, 23, 5, 3, Black, HIDE_DISABLE);
        }
    }
//    if((BR1189_steer_status.hourmeter_counter_flag == HM_COUNTER_ON) || (BR1189_trac_status.hourmeter_counter_flag == HM_COUNTER_ON) \
//     || (BR1189_lift_status.hourmeter_counter_flag == HM_COUNTER_ON))
    if(BR1189_trac_status.hourmeter_counter_flag == HM_COUNTER_ON)
    {
        Display_hour_counter_sign(HIDE_DISABLE);
    }
    else
    {
        Display_hour_counter_sign(HIDE_ENABLE);
    }

}/*end of Display_battary_col()*/

/**
* @brief	Display Time and Data
            America time is 12 hour, format yy-mm-dd;
            Eurpo time is 24 hour, format dd-mm-yy
* @param	current_time: t_tm time structure
            area: America or Eurpo
* @note     none
* @retval   none  
*/
void Display_data_time(t_tm current_time, u8 area)
{
    U8 year_temp[4], mon_temp[2], date_temp[2], hour_temp[2], min_temp[2], sec_temp[2];
    S8 hour;
    U8 start_col_data = 26;
    U8 start_col_time = 26;
  
    if(area > 3)
    {
        area = 0;
    }
    year_temp[0] = current_time.t_year / 1000;
    year_temp[1] = (current_time.t_year -  year_temp[0] * 1000) / 100;
    year_temp[2] = (current_time.t_year - year_temp[0] * 1000 - year_temp[1] * 100)  / 10;
    year_temp[3] = current_time.t_year - year_temp[0] * 1000 - year_temp[1] * 100 - year_temp[2] * 10;
    mon_temp[0] = current_time.t_mounth / 10;
    mon_temp[1] = current_time.t_mounth - mon_temp[0] * 10;
    date_temp[0] = current_time.t_date / 10;
    date_temp[1] = current_time.t_date - date_temp[0] * 10;
    hour = current_time.t_hour;
    min_temp[0] = current_time.t_min / 10;
    min_temp[1] = current_time.t_min - min_temp[0] * 10;
    sec_temp[0] = current_time.t_sec / 10;
    sec_temp[1] = current_time.t_sec - sec_temp[0] * 10;
    hour_temp[0] = hour / 10;
    hour_temp[1] = hour - hour_temp[0] * 10;
    
    LCD_draw_number(2, start_col_data, SIZE_10, year_temp[2], HIDE_DISABLE );
    LCD_draw_number(2, start_col_data + 8, SIZE_10, year_temp[3], HIDE_DISABLE );
    LCD_draw_sign(2, start_col_data + 16, SIZE_10, 1 );
    LCD_draw_number(2, start_col_data + 24, SIZE_10, mon_temp[0], HIDE_DISABLE );
    LCD_draw_number(2, start_col_data + 32, SIZE_10, mon_temp[1], HIDE_DISABLE );
    LCD_draw_sign(2, start_col_data + 40, SIZE_10, 1 );
    LCD_draw_number(2, start_col_data + 48, SIZE_10, date_temp[0], HIDE_DISABLE );
    LCD_draw_number(2, start_col_data + 56, SIZE_10, date_temp[1], HIDE_DISABLE );

    LCD_draw_number(4, start_col_time, SIZE_10, hour_temp[0], HIDE_DISABLE );
    LCD_draw_number(4, start_col_time + 8, SIZE_10, hour_temp[1], HIDE_DISABLE );
    LCD_draw_sign(4, start_col_time + 16, SIZE_10, 2 );
    /*if((current_time.t_sec % 2) == 1)
    {
        LCD_draw_sign(4, start_col_time + 16, SIZE_10, 2 );
    }
    else
    {
        LCD_draw_sign(4, start_col_time + 16, SIZE_10, 8 );
    }		*/
    LCD_draw_number(4, start_col_time + 24, SIZE_10, min_temp[0], HIDE_DISABLE );
    LCD_draw_number(4, start_col_time + 32, SIZE_10, min_temp[1], HIDE_DISABLE );
    LCD_draw_sign(4, start_col_time + 40, SIZE_10, 2 );
    LCD_draw_number(4, start_col_time + 48, SIZE_10, sec_temp[0], HIDE_DISABLE );
    LCD_draw_number(4, start_col_time + 56, SIZE_10, sec_temp[1], HIDE_DISABLE );	
}/*end of Display_data_time()*/

/**
* @brief	Display hour counter sign
            If hour meter enable, the sign will show on the fixed area
* @param	is_hide: HIDE_ENABLE---hide, HIDE_DISABLE---show
* @note     none
* @retval   none  
*/
void Display_hour_counter_sign(U8 is_hide)
{
    u8 i, j;
    if(is_hide == HIDE_DISABLE)
    {
//		LCD_draw_rectangle( 102, 17, 9, 9, White, HIDE_DISABLE );
//		LCD_draw_line( 102, 17,  110, 25 );
//		LCD_draw_line( 110, 17,  102, 25 );
        for(i = 0; i < 2; i ++)
        {
            for(j = 0; j < 8; j ++)
            {
                OLED_GRAM[2 + i][102 + j] = time_log[i * 8 + j];
            }
        }
    }
    else if(is_hide == HIDE_ENABLE)
    {
        LCD_ersea_area( 102, 16, 8, 16 );
    }
}/*end of Display_hour_counter_sign()*/

/**
* @brief	Display the scrollbar's status on the right side of LCD
* @param	status: 0~15, 0: scrollbar hide
* @note     none
* @retval   none  
*/
void Display_scrollbar(U8 status)
{
    switch(status)
    {
        case 0:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_ENABLE, HIDE_ENABLE, HIDE_ENABLE );break;
        case 1:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_ENABLE, HIDE_ENABLE, HIDE_DISABLE );break;
        case 2:	 LCD_draw_scrollbar( HIDE_ENABLE, HIDE_ENABLE, HIDE_DISABLE, HIDE_ENABLE );break;
        case 3:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_ENABLE, HIDE_DISABLE, HIDE_DISABLE );break;
        case 4:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_DISABLE, HIDE_ENABLE, HIDE_ENABLE );break;
        case 5:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_DISABLE, HIDE_ENABLE, HIDE_DISABLE );break;
        case 6:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_DISABLE, HIDE_DISABLE, HIDE_ENABLE );break;
        case 7:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_DISABLE, HIDE_DISABLE, HIDE_DISABLE );break;
        case 8:  LCD_draw_scrollbar( HIDE_DISABLE, HIDE_ENABLE, HIDE_ENABLE, HIDE_ENABLE );break;
        case 9:  LCD_draw_scrollbar( HIDE_DISABLE, HIDE_ENABLE, HIDE_ENABLE, HIDE_DISABLE );break;
        case 10: LCD_draw_scrollbar( HIDE_DISABLE, HIDE_ENABLE, HIDE_DISABLE, HIDE_ENABLE );break;	 
        case 11: LCD_draw_scrollbar( HIDE_DISABLE, HIDE_ENABLE, HIDE_DISABLE, HIDE_DISABLE );break;
        case 12: LCD_draw_scrollbar( HIDE_DISABLE, HIDE_DISABLE, HIDE_ENABLE, HIDE_ENABLE );break;
        case 13: LCD_draw_scrollbar( HIDE_DISABLE, HIDE_DISABLE, HIDE_ENABLE, HIDE_DISABLE );break;
        case 14: LCD_draw_scrollbar( HIDE_DISABLE, HIDE_DISABLE, HIDE_DISABLE, HIDE_ENABLE );break;
        case 15: LCD_draw_scrollbar( HIDE_DISABLE, HIDE_DISABLE, HIDE_DISABLE, HIDE_DISABLE );break;
        default: break;
    }
}/*end of Display_scrollbar()*/

/**
* @brief	Display the hour meter on the fixed location of LCD
* @param	hour_counter: hour meter time
            is_hide: hide or show
* @note     none
* @retval   none  
*/
void Display_hour_meter(S32 hour_counter, U8 is_hide)
{
    U8 hour_counter_temp[6];
    U8 Start_x = 13;
    U8 Start_y = 5;
    U8 i, j, zero_num = 0;
    U8 k;
    if((hour_counter < 0) || (hour_counter > 999999))
    {
        return;
    }
    if(is_hide == HIDE_DISABLE)
    {
        //Clear the hour meter areas
        for(i = 0; i < 2; i ++)
        {
            for(j = 0; j < 118; j++)
            {
                OLED_GRAM[i + Start_y][j + Start_x] = 0x00;
            }
        }	
        hour_counter_temp[0] = hour_counter / 100000;
        hour_counter_temp[1] = (hour_counter - hour_counter_temp[0] * 100000) / 10000;
        hour_counter_temp[2] = (hour_counter - hour_counter_temp[0] * 100000 - hour_counter_temp[1] * 10000) / 1000;
        hour_counter_temp[3] = (hour_counter - hour_counter_temp[0] * 100000 - hour_counter_temp[1] * 10000 - hour_counter_temp[2] * 1000) / 100;
        hour_counter_temp[4] = (hour_counter - hour_counter_temp[0] * 100000 - hour_counter_temp[1] * 10000 - hour_counter_temp[2] * 1000 - hour_counter_temp[3] * 100) / 10;
        hour_counter_temp[5] = hour_counter - hour_counter_temp[0] * 100000 - hour_counter_temp[1] * 10000 - hour_counter_temp[2] * 1000 - hour_counter_temp[3] * 100 - hour_counter_temp[4] * 10;
        
        //Search how much 0 ahead of the hourcounter
        for(k = 0; k < 6; k ++)
        {
            if(hour_counter_temp[k] == 0)
            {
                zero_num ++;
            }
            else
            {
                break;
            }
        }
        //if all the hour_counter_temp are 0, then display a '0h'
        if(zero_num == 6)
        {
            zero_num = 5;
        }
        // calculate the start x column
        Start_x = (118 - (6 - zero_num) * 13) / 2;
        for(k = zero_num; k < 6; k ++)
        {
            LCD_draw_number(Start_y, Start_x + 13 * (k - zero_num), SIZE_12, hour_counter_temp[k], HIDE_DISABLE );
        }
        for(i = 0; i < 2; i ++)
        {
            for(j = 0; j < 13; j++)
            {
                OLED_GRAM[i + Start_y][j + Start_x + 13 * (k - zero_num)] = char_h_lower_Size12[i * 13 + j];
            }
        }		
    }
    else
    {
        for(i = 0; i < 2; i ++)
        {
            for(j = 0; j < 118; j++)
            {
                OLED_GRAM[i + Start_y][j + Start_x] = 0x00;
            }
        }	
    }
}/*end of display_hour_meter()*/

/**
* @brief	Display adjust bar on the lcd to adjust the brightness and the contrast
* @param	bar_kind: Choose the display bar kind.
                      CONTRAST_BAR: Adjust the contrast
                      LIGHTING_BAR: Adjust the loghting
            value: Adjust value from 0~7
            is_hide: hide or show
* @note     none
* @retval   none  
*/
void Display_adjust_bar( U8 bar_kind, S16 value , U8 is_hide)
{
    U8 Start_x = 3;
    U8 Start_y = 40;
    U8 i;
//	if((value < 0) || (value > 6))
//	{
//		return;
//	}
    if(value < 0)
    {
        value = 0;
    }
    else if(value > 6)
    {
        value = 6;
    }
    if(is_hide == HIDE_DISABLE)
    {
        LCD_draw_rectangle( Start_x, Start_y, 3, 16, White, HIDE_DISABLE);
        if(bar_kind == CONTRAST_BAR)
        {           
            put_string(5, Start_x + 15, SIZE_7, "CONTRAST", HIDE_DISABLE);
        }
        else if(bar_kind == LIGHTING_BAR)
        {
            if(Language == LANGUAGE_EN )
            {
                put_string(5, Start_x + 15, SIZE_7, "Lighting", HIDE_DISABLE);
            }
            else if(Language == LANGUAGE_CH )
            {
                Display_Light_ch_pic();
            }
        }
        
        LCD_draw_rectangle( Start_x + 64 , Start_y, 3, 16, Black, HIDE_DISABLE);
        for(i = 0; i < 9; i ++)
        {
            LCD_draw_rectangle( Start_x + i * 8 , 59, 3, 3, White, HIDE_DISABLE);
        }
        //Clear the bar area
        for(i = Start_x + 8; i < Start_x + 59; i ++)
        {
            OLED_GRAM[6][i] = 0x00;
        }	
        LCD_draw_rectangle( Start_x + ((value + 1) * 8) , 53, 3, 3, Black, HIDE_DISABLE); 
    }
}/*end of Display_adjust_bar()*/
/**
* @brief	Display welcome picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_welcome_pic(void)
{
    u8 i, j;
    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i][j] = welcome_pic_cn[i][j];
        }
    }
}// end Display_welcome_pic() 

/**
* @brief	Display pin code chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_pincode_ch_pic(void)
{
    u8 i, j;
    for(i = 0; i < 3; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i + 1][j] = input_pincode_cn[i * 128 + j];
        }
    }
}// end Display_pincode_ch_pic() 
/**
* @brief	Display pin code chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_Light_ch_pic(void)
{
    u8 i, j;
    for(i = 0; i < 2; i ++)
    {
        for(j = 0; j < 44; j ++)
        {
            OLED_GRAM[i + 4][j + 15] = back_light_cn[i * 44 + j];
        }
    }
}// end Display_pincode_ch_pic()
/**
* @brief	Display next service time chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_next_service_ch_pic(void)
{
    u8 i, j;
    for(i = 0; i < 2; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i + 5][j] = next_service_time_cn[i * 128 + j];
        }
    }
}// end void Display_next_service_ch_pic(void)
/**
* @brief	Display  tempurature too high chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_MotoTemp_tooHigh1_ch(void)
{
    u8 i, j;
    for(i = 0; i < 2; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i + 4][j] = moto_tempurature_too_high1_cn[i * 128 + j];
        }
    }
}// end void Display_MotoTemp_tooHigh1_ch(void)

/**
* @brief	Display oil lack chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_OilLack_ch(void)
{
    u8 i, j;
    for(i = 0; i < 4; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i + 4][j] = oil_lack_cn[i * 128 + j];
        }
    }
}// end void Display_OilLack_ch(void)
/**
* @brief	Display oil lack chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_Maintance_ch(void)
{
    u8 i, j;
    for(i = 0; i < 4; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i + 4][j] = maintance_info_cn[i * 128 + j];
        }
    }
}// end void Display_OilLack_ch(void)
/**
* @brief	Display battery cut off chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_BatteryCutOff_ch(void)
{
    u8 i, j;
    for(i = 0; i < 4; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i + 4][j] = bat_cutoff_info_cn[i * 128 + j];
        }
    }
}// end void Display_BatteryCutOff_ch(void)
/**
* @brief	Display battery low chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_Batlow_ch(void)
{
    u8 i, j;
    batt_flash_counter ++;
    if(batt_flash_counter >= 6)
    {
        batt_flash_counter = 0;
    }
    for(i = 0; i < 4; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            if(batt_flash_counter <= 2)
            {
                OLED_GRAM[i + 4][j] = bat_low_info_cn[0][i * 128 + j];
            }
            else
            {
                OLED_GRAM[i + 4][j] = bat_low_info_cn[1][i * 128 + j];
            }
            
        }
    }	
}
/**
* @brief	Display tempurature too high chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_MotoTemp_tooHigh2_ch(void)
{
    u8 i, j;
    for(i = 0; i < 4; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i + 4][j] = moto_tempurature_too_high2_cn[i * 128 + j];
        }
    }
}// end void Display_MotoTemp_tooHigh2_ch(void)

/**
* @brief	Display pin code chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_Confirm_Delete_ch(void)
{
    u8 i, j;
    for(i = 0; i < 4; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i + 4][j] = delete_confirm_cn[i * 128 + j];
        }
    }
}// end void Display_OilLack_ch(void)
/**
* @brief	put string on the lcd
* @param	start_row: Start page, from 0 ~ 7
            start_column: Start column, from 0 ~ 127
            *string: The string you want to display
            is_hide: hide or show
* @note     none
* @retval   none  
*/
void put_string(S16 start_row, S16 start_column, font_size size, char *string, U8 is_hide)
{
    char character;
    char number;
    if(is_hide == HIDE_DISABLE)
    {
        do
        {
            character = *string;
            if((character >= 65) && (character <= 90))
            {
                LCD_draw_upperchar(start_row, start_column, size, character, HIDE_DISABLE);
                
            }
            else if((character >= 48) && (character <= 57))
            {
                number = character - 48;
                LCD_draw_number(start_row, start_column, size, number, HIDE_DISABLE);
            }
            else if((character >= 97) && (character <= 122))
            {
                LCD_draw_lowerchar(start_row, start_column, size, character, HIDE_DISABLE);			
            }
            else
            {
                switch (character)
                {
                    case '%': LCD_draw_sign( start_row, start_column, size, 0); break;	//Display '%'
                    case '/': LCD_draw_sign( start_row, start_column, size, 1); break;	//Display '/'
                    case ':': LCD_draw_sign( start_row, start_column, size, 2); break;	//Display ':'
                    case '!': LCD_draw_sign( start_row, start_column, size, 3); break;	//Display '!'
                    case '+': LCD_draw_sign( start_row, start_column, size, 4); break;	//Display '+'
                    case '-': LCD_draw_sign( start_row, start_column, size, 5); break;	//Display '-'
                    case ';': LCD_draw_sign( start_row, start_column, size, 6); break;	//Display ';'
                    case '.': LCD_draw_sign( start_row, start_column, size, 7); break;	//Display '.'
                    case ' ': LCD_draw_sign( start_row, start_column, size, 8); break;	//Display ' '
                    case '*': LCD_draw_sign( start_row, start_column, size, 9); break;	//Display ' '
                    case '?': LCD_draw_sign( start_row, start_column, size, 10); break;	//Display ' '
                    default: break;
                }
            }		
            if(size == SIZE_7)
            {
                // To adjust the distence between to near characters
                if((character == 'I') || (character == 'i') || (character == 'l') || (character == '!') || (character == '.') )
                {
                    start_column += 2;
                }
                else if((character == 'j') || (character == ':') || (character == ';')\
                    || (character == ' ') )
                {
                    start_column += 3;
                }
                else if((character == 'E') || (character == 'F')|| (character == 'J')|| (character == 'L')\
                    || (character == 'f') || (character == 's') || (character == 't') || (character == '1'))
                {
                    start_column += 4;
                }
                else if((character == 'Z') || (character == '4'))
                {
                    start_column += 7;
                }
                else if((character == 'M') || (character == 'W') || (character == 'w') || (character == '*'))
                {
                    start_column += 8;
                }
                else if(character == '%')
                {
                    start_column += 9;
                }
                else
                {
                    start_column += 6;
                }
            }
            else if(size == SIZE_10)
            {
                if((character == 'I') || (character == 'l'))
                {
                    start_column += 3;
                }
                else if((character == 'J') || (character == 'i')|| (character == ':')|| (character == '!')|| (character == ';')|| (character == '.')|| (character == ' '))
                {
                    start_column += 4;
                }
                else if((character == '4') || (character == 'E') || (character == 'F') ||(character == 'L') \
                    || (character == 'f')|| (character == 'j')||(character == 'r')||(character == 's')||(character == 't'))
                {
                    start_column += 6;
                }
                else if((character == 'C') || (character == 'P') ||(character == 'S') || (character == 'T')\
                    || (character == 'Z')||(character == 'a')||(character == 'c')||(character == 'e') ||(character == 'k')\
                    || (character == '0')||(character == '2')||(character == '3')||(character == '4') ||(character == '5')\
                    || (character == '6')||(character == '7')||(character == '8')||(character == '9'))
                {
                    start_column += 7;
                }
                else if((character == 'A') || (character == 'V') ||(character == 'X') || (character == 'v')\
                    || (character == 'x')||(character == 'y')||(character == '+'))
                {
                    start_column += 9;
                }
                else if(character == 'M')
                {
                    start_column += 10;
                }
                else if((character == '*')||(character == '-'))
                {
                    start_column += 11;
                }
                else if((character == 'W')|| (character == 'm') ||(character == 'w'))
                {
                    start_column += 12;
                }
                else if(character == '%')
                {
                    start_column += 13;
                }
                else
                {
                    start_column += 8;
                }
            }
            
            string ++;
        }
        while(character != '\0');
    }
}/*end of put_string()*/

void show_hourmeter_number(S16 start_row, U32 hourmeter_10times)
{
    u8 temp_data[6], i, zero_bit_num = 0, start_column;
    if(hourmeter_10times > 100000)
        return;
    temp_data[0] = hourmeter_10times / 100000;
    temp_data[1] = (hourmeter_10times - temp_data[0] * 100000) / 10000;
    temp_data[2] = (hourmeter_10times - temp_data[0] * 100000 - temp_data[1] * 10000) / 1000;
    temp_data[3] = (hourmeter_10times - temp_data[0] * 100000 - temp_data[1] * 10000 - temp_data[2] * 1000) / 100;
    temp_data[4] = (hourmeter_10times - temp_data[0] * 100000 - temp_data[1] * 10000 - temp_data[2] * 1000 - temp_data[3] * 100 ) / 10;
    temp_data[5] = hourmeter_10times - temp_data[0] * 100000 - temp_data[1] * 10000 - temp_data[2] * 1000 - temp_data[3] * 100 - temp_data[4] * 10;
    for(i = 0; i < 4; i ++)
    {
        if(temp_data[i] == 0)
        {
            zero_bit_num ++;
        }
        else
        {
             break;
        }     
    }
    start_column = 64 - (((4 - zero_bit_num) * 6 + 23) / 2);                 // find the adapt location of x pos
    for(i = zero_bit_num; i < 4; i ++)
    {
        LCD_draw_number(start_row, start_column, SIZE_7, temp_data[i], HIDE_DISABLE);
        start_column += 6;
    }
    LCD_draw_number(start_row, start_column, SIZE_7, temp_data[4], HIDE_DISABLE);
    start_column += 6;
    LCD_draw_sign( start_row, start_column, SIZE_7, 7);                        // '.'
    start_column += 2;
    LCD_draw_number(start_row, start_column, SIZE_7, temp_data[5], HIDE_DISABLE);
    start_column += 6;
    LCD_draw_sign( start_row, start_column, SIZE_7, 8);                        // ' ' 
    start_column += 3;
    LCD_draw_lowerchar(start_row, start_column, SIZE_7, 'h', HIDE_DISABLE);	
}/*end of show_hourmeter_number()*/

void show_service_hour(S16 start_row, U32 service_hour)
{
    u8 temp_data[6], i, zero_bit_num = 0, start_column;
    if(service_hour > 100000)
        return;
    temp_data[0] = service_hour / 100000;
    temp_data[1] = (service_hour - temp_data[0] * 100000) / 10000;
    temp_data[2] = (service_hour - temp_data[0] * 100000 - temp_data[1] * 10000) / 1000;
    temp_data[3] = (service_hour - temp_data[0] * 100000 - temp_data[1] * 10000 - temp_data[2] * 1000) / 100;
    temp_data[4] = (service_hour - temp_data[0] * 100000 - temp_data[1] * 10000 - temp_data[2] * 1000 - temp_data[3] * 100 ) / 10;
    temp_data[5] = service_hour - temp_data[0] * 100000 - temp_data[1] * 10000 - temp_data[2] * 1000 - temp_data[3] * 100 - temp_data[4] * 10;
    for(i = 0; i < 5; i ++)
    {
        if(temp_data[i] == 0)
        {
            zero_bit_num ++;
        }
        else
        {
             break;
        }     
    }
    start_column = 64 - (((5 - zero_bit_num) * 6 + 23) / 2);                 // find the adapt location of x pos
    for(i = zero_bit_num; i < 5; i ++)
    {
        LCD_draw_number(start_row, start_column, SIZE_7, temp_data[i], HIDE_DISABLE);
        start_column += 6;
    }
    LCD_draw_number(start_row, start_column, SIZE_7, temp_data[5], HIDE_DISABLE);
    start_column += 6;
    LCD_draw_sign( start_row, start_column, SIZE_7, 8);                        // ' ' 
    start_column += 3;
    LCD_draw_lowerchar(start_row, start_column, SIZE_7, 'h', HIDE_DISABLE);	
}/*end of show_hourmeter_number()*/

/**
* @brief	Display pin code chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_admin_pincode_ch_pic(void)
{
    u8 i, j;
    for(i = 0; i < 3; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i + 1][j] = input_adminpincode_cn[i * 128 + j];
        }
    }
}// end Display_pincode_ch_pic() 

void Display_enter_pincode_ch_pic(void)
{
    u8 i, j;
    for(i = 0; i < 3; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i + 1][j] = input_enternewpincode_cn[i * 128 + j];
        }
    }
}

/**
* @brief	Display add pin code confirm chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_Confirm_AddPincode_ch(void)
{
    u8 i, j;
    for(i = 0; i < 4; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i + 4][j] = add_pincode_confirm_cn[i * 128 + j];
        }
    }
}// end void Display_Confirm_AddPincode_ch(void)

/**
* @brief	Display add pin code chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_NewPincode_ch(void)
{
    u8 i, j;
    for(i = 0; i < 2; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i][j] = new_pincode_cn[i * 128 + j];
        }
    }
}// end void Display_OilLack_ch(void)

/************************************Test program function****************************/
/**
* @brief	Display start test picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_starttest_pic(void)
{
    u8 i, j;
    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i][j] = starttest_pic_cn[i][j];
        }
    }
}// end Display_welcome_pic()

/**
* @brief	Display start test picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_ledtest1_pic(U8 test_progress)
{
    u8 i, j;
    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            switch (test_progress)
            {
                case 2: 
                {
                    OLED_GRAM[i][j] = ledtest1_pic_cn[i][j]; 
                    put_string(3, 5, SIZE_7, "BDI:", HIDE_DISABLE);                   
                    put_string(4, 5, SIZE_7, "Calibration:", HIDE_DISABLE);
                    Display_battary_col1(BDI_BattCon);
                    Display_cal(BDI_vbatt_cal[0]);
                    break;
                }
                case 3: OLED_GRAM[i][j] = ledtest2_pic_cn[i][j]; break;
                case 4: OLED_GRAM[i][j] = ledtest3_pic_cn[i][j]; break;
                case 5: OLED_GRAM[i][j] = ledtest4_pic_cn[i][j]; break;
                case 6: OLED_GRAM[i][j] = ledtest5_pic_cn[i][j]; break;
                case 7: OLED_GRAM[i][j] = ledtest6_pic_cn[i][j]; break;
                default : break;
            }
        }
    }
}// end Display_welcome_pic()
/**
* @brief	Display lcd test picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_lcdtest1_pic(U8 test_progress)
{
    u8 i, j;
    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            switch (test_progress)
            {
                case 1: OLED_GRAM[i][j] = lcdtest1_pic_cn[i][j]; break;
                case 2: OLED_GRAM[i][j] = ~lcdtest1_pic_cn[i][j]; break;
                case 3: OLED_GRAM[i][j] = 0xff; break;
                case 4: OLED_GRAM[i][j] = 0x00; break;
                case 5: OLED_GRAM[i][j] = lcdtest2_pic_cn[i][j]; break;
                default : break;
            }
        }
    }
}// end Display_lcdtest1_pic()

/**
* @brief	Display key test picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_keytest1_pic(U8 test_progress)
{
    u8 i, j;
    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            switch (test_progress)
            {
                case 10: OLED_GRAM[i][j] = keytest1_pic_cn[i][j]; break;
                case 11: OLED_GRAM[i][j] = keytest2_pic_cn[i][j]; break;
                case 12: OLED_GRAM[i][j] = keytest3_pic_cn[i][j]; break;
                case 13: OLED_GRAM[i][j] = keytest4_pic_cn[i][j]; break;
                case 14: OLED_GRAM[i][j] = keytest5_pic_cn[i][j]; break;
                default : break;
            }
        }
    }
}// end Display_keytest1_pic()

/**
* @brief	Display eeprom test picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_e2promtest1_pic(U8 test_progress)
{
    u8 i, j;
    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            switch (test_progress)
            {
                case 15: OLED_GRAM[i][j] = e2promtest1_pic_cn[i][j]; break;
                case 16: OLED_GRAM[i][j] = e2promtest2_pic_cn[i][j]; break;
                case 17: OLED_GRAM[i][j] = e2promtest3_pic_cn[i][j]; break;
                case 18: OLED_GRAM[i][j] = e2promtest4_pic_cn[i][j]; break;
                default : break;
            }
        }
    }
}// end Display_e2promtest1_pic()

void Display_hw_version(S16 start_row, S16 start_col, U32 hw_ver)
{
    u8 temp_data[4];

    if(hw_ver > 9999)
    {
        hw_ver = 0;
    }
    temp_data[0] = hw_ver / 1000;
    temp_data[1] = (hw_ver - temp_data[0] * 1000) / 100;
    temp_data[2] = (hw_ver - temp_data[0] * 1000 - temp_data[1] * 100) / 10;
    temp_data[3] = hw_ver - temp_data[0] * 1000 - temp_data[1] * 100 - temp_data[2] * 10;

    LCD_draw_number(start_row, start_col, SIZE_7, temp_data[0], HIDE_DISABLE);
    start_col += 6;
    LCD_draw_sign( start_row, start_col, SIZE_7, 7);
    start_col += 6;
    LCD_draw_number(start_row, start_col, SIZE_7, temp_data[1], HIDE_DISABLE);
    start_col += 6;
    LCD_draw_number(start_row, start_col, SIZE_7, temp_data[2], HIDE_DISABLE);
    start_col += 6;
    LCD_draw_number(start_row, start_col, SIZE_7, temp_data[3], HIDE_DISABLE);
}/*end of show_hourmeter_number()*/


void Display_buzzer_pic(void)
{
    u8 i, j;
    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i][j] = buzzertest1_pic_cn[i][j];
        }
    }
}/*end of show_hourmeter_number()*/

void Display_ADtest1_pic(U32 AD_value)
{
    u8 temp_data[4];
    u8 i, j;

    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i][j] = adctest1_pic_cn[i][j];
        }
    }

    if(AD_value > 9999)
    {
        AD_value = 0;
    }
    temp_data[0] = AD_value / 1000;
    temp_data[1] = (AD_value - temp_data[0] * 1000) / 100;
    temp_data[2] = (AD_value - temp_data[0] * 1000 - temp_data[1] * 100) / 10;
    temp_data[3] = AD_value - temp_data[0] * 1000 - temp_data[1] * 100 - temp_data[2] * 10;

    LCD_draw_number(3, 65, SIZE_7, temp_data[0], HIDE_DISABLE);
    LCD_draw_number(3, 71, SIZE_7, temp_data[1], HIDE_DISABLE);
    LCD_draw_number(3, 77, SIZE_7, temp_data[2], HIDE_DISABLE);
    LCD_draw_number(3, 83, SIZE_7, temp_data[3], HIDE_DISABLE);

    temp_data[0] = BDI_VBatt / 1000;
    temp_data[1] = (BDI_VBatt - temp_data[0] * 1000) / 100;
    temp_data[2] = (BDI_VBatt - temp_data[0] * 1000 - temp_data[1] * 100) / 10;
    temp_data[3] = BDI_VBatt - temp_data[0] * 1000 - temp_data[1] * 100 - temp_data[2] * 10;
    LCD_draw_number(5, 65, SIZE_7, temp_data[0], HIDE_DISABLE);
    LCD_draw_number(5, 71, SIZE_7, temp_data[1], HIDE_DISABLE);
    LCD_draw_sign(5, 77, SIZE_7, 7);
    LCD_draw_number(5, 83, SIZE_7, temp_data[2], HIDE_DISABLE);
    LCD_draw_number(5, 89, SIZE_7, temp_data[3], HIDE_DISABLE);
    LCD_draw_upperchar( 5, 96, SIZE_7, 'V', HIDE_DISABLE);
}

void Display_PWMtest1_pic(U8 pwm_level)
{
    u8 i, j;
    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            switch (pwm_level)
            {
                case 21: OLED_GRAM[i][j] = pwmtest1_pic_cn[i][j]; break;
                case 22: OLED_GRAM[i][j] = pwmtest2_pic_cn[i][j]; break;
                case 23: OLED_GRAM[i][j] = pwmtest3_pic_cn[i][j]; break;
                case 24: OLED_GRAM[i][j] = pwmtest4_pic_cn[i][j]; break;
                case 25: OLED_GRAM[i][j] = pwmtest5_pic_cn[i][j]; break;
                default : break;
            }
        }
    }
}

void Display_CANTransmittest1_pic(void)
{
    u8 i, j;
    U8 temp_data[2];
    U8 start_col = 0;
    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i][j] = cantransmittest1_pic_cn[i][j];
        }
    }
    for (i = 0; i < 8; i ++)
    {
        temp_data[0] = test_can_transmit_buf[i] / 16;
        temp_data[1] = test_can_transmit_buf[i] - temp_data[0] * 16;
        LCD_draw_number(5, start_col, SIZE_7, temp_data[0], HIDE_DISABLE);
        LCD_draw_number(5, start_col + 6, SIZE_7, temp_data[1], HIDE_DISABLE);
        start_col += 15;
    }
}

void Display_CANReceivetest1_pic(void)
{
    u8 i, j;
    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i][j] = canreceivetest1_pic_cn[i][j];
        }
    }
    Display_number(4, 18, test_can_buff[0]);
    Display_number(4, 42, test_can_buff[1]);
    Display_number(4, 66, test_can_buff[2]);
    Display_number(4, 90, test_can_buff[3]);

    Display_number(5, 18, test_can_buff[4]);
    Display_number(5, 42, test_can_buff[5]);
    Display_number(5, 66, test_can_buff[6]);
    Display_number(5, 90, test_can_buff[7]);
}

void Display_number(S16 start_row, S16 start_col, U8 number)
{
    u8 temp_data[3];
    temp_data[0] = number / 256;
    temp_data[1] = (number - temp_data[0] * 256) / 16;
    temp_data[2] = number - temp_data[0] * 256 - temp_data[1] * 16;

    LCD_draw_number(start_row, start_col, SIZE_7, temp_data[0], HIDE_DISABLE);
    LCD_draw_number(start_row, start_col + 6, SIZE_7, temp_data[1], HIDE_DISABLE);
    LCD_draw_number(start_row, start_col + 12, SIZE_7, temp_data[2], HIDE_DISABLE);
}

void Display_exit1_pic(void)
{
    u8 i, j;
    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i][j] = exittest1_pic_cn[i][j];
        }
    }    
}

void Display_Rtctest1_pic(void)
{
    u8 i, j;

    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 128; j ++)
        {
            OLED_GRAM[i][j] = rtctest1_pic_cn[i][j];
        }
    }
    Display_data_time(sys_time, date_format);
}
void Display_battary_col1( U8 bat_col)
{
    U8 i, j, k;

    i = bat_col / 100;
    j = (bat_col - i * 100) / 10;
    k = bat_col - i * 100 - j * 10;
    if(i == 0)
    {
        LCD_draw_number( 3, 30, SIZE_7, i, HIDE_ENABLE );
    } 
    else
    {
        LCD_draw_number( 3, 30, SIZE_7, i, HIDE_DISABLE );
    }
    if((j == 0) && (i == 0))
    {
        LCD_draw_number(3, 36, SIZE_7, j, HIDE_ENABLE );
    }
    else
    {
        LCD_draw_number(3, 36, SIZE_7, j, HIDE_DISABLE );
    }
    LCD_draw_number(3, 42, SIZE_7, k, HIDE_DISABLE );		
    LCD_draw_sign(3,48,SIZE_7,0);

}/*end of Display_battary_col()*/

void Display_cal( U16 cal_val)
{
    u8 temp_data[4];
    temp_data[0] = cal_val / 4096;
    temp_data[1] = (cal_val - temp_data[0] * 4096) / 256;
    temp_data[2] = (cal_val - temp_data[0] * 4096 - temp_data[1] * 256) / 16;
    temp_data[3] = cal_val - temp_data[0] * 4096 - temp_data[1] * 256 - temp_data[2] * 16;

    //LCD_draw_number( 4, 78, SIZE_7, temp_data[0], HIDE_DISABLE );
    LCD_draw_number( 4, 78, SIZE_7, temp_data[1], HIDE_DISABLE );
    LCD_draw_number( 4, 85, SIZE_7, temp_data[2], HIDE_DISABLE );
    LCD_draw_number( 4, 91, SIZE_7, temp_data[3], HIDE_DISABLE );

}/*end of Display_battary_col()*/

/***********************************************************************************************************************
*                             Copyright 2016 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/


